package com.zlfund.cat.zjgsmk.util.filepick;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.File;

/**
 * Created by chenj on 2017/9/26 0026.
 */

public class SizeFileFilter implements IFileFilterService {

    private int mHeight;
    private int mWidth;
    private Bitmap mBm;

    public SizeFileFilter(int width, int height){
        mWidth = width;
        mHeight = height;
    }

    @Override
    public boolean filterFile(File file) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        mBm = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
        if (mBm == null) {
            return true;
        }
        int width = mBm.getWidth();
        int height = mBm.getHeight();
        mBm.recycle();
        mBm = null;
        return !(width >= mWidth && height >= mHeight);
    }

    public int getHeight() {
        return mHeight;
    }

    public void setHeight(int height) {
        mHeight = height;
    }

    public int getWidth() {
        return mWidth;
    }

    public void setWidth(int width) {
        mWidth = width;
    }
}
